package API.AboutTime.SimpleDateFormatAPI;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

//将日期字符串转变为Date对象(用于转换的SimpleDateFormat的相应格式应与字符串保持一致)
public class StringToDate {
    public static void main(String[] args) {
        String strDate = "2023-9-30 12:00:00";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date = sdf.parse(strDate);
            System.out.println(date);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
}
